/**
 * Created by own on 2017/12/7.
 */
//var url = 'http://edu.yzztnet.com/public/api/index.php/jiajiao/interface/';
function geturlcanshu() {

    /* 用途: 接收地直栏参数 取id=1 根据ID的值 */
    var urlinfo = decodeURI(window.location.href); //获取当前页面的url
    var len = urlinfo.length;//获取url的长度
    var offset = urlinfo.indexOf("?");//设置参数字符串开始的位置
    var newsidinfo = urlinfo.substr(offset, len).replace('&', '');//取出参数字符串 这里会获得类似“id=1”这样的字符串
    newsidinfo = newsidinfo.replace('?id', '');
    newsidinfo = newsidinfo.replace('name', '');
    //console.log(newsidinfo);
    var newsids = newsidinfo.split("=");//对获得的参数字符串按照“=”进行分割
    return newsids;
}
//格式化时间戳函数
function formatDateTime(timeStamp) {
    var date = new Date();
    date.setTime(timeStamp * 1000);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
};

var newsids = geturlcanshu();
var id = newsids[1];
sessionStorage.setItem('id', id);
var name = newsids[2];

$.ajax({
    url: url + 'gettechdetails?id=' + id,
    type: 'post',
    data: {},
    dataType: 'json',
    async: 'true',
    timeout: 2000,
    success: function (data) {
        if (data.code == 1000 && data.status == 1) {
            var teDetails = data.data;
            $('title').text(teDetails['teachers']['xingming'] + '详细页面');
            var liHl = '<li><span>姓名:</span><span>' + teDetails['teachers']['xingming'] + '</span></li>'
                + '<li><span>毕业院校:</span><span>' + teDetails['teachers']['yuanxiao'] + '</span></li>'
                + '<li><span>工作单位:</span><span>' + teDetails['teachers']['danwei'] + '</span></li>'
                + '<li><span>剧种:</span><span>' + teDetails['teachers']['juzhong'] + '</span></li>'
                + '<li><span>行当:</span><span>' + teDetails['teachers']['hangdang'] + '</span></li>';
            $('#teacherinfo>ul').html(liHl);

            if (teDetails['teachers']['jianjie'] == '') {
                teDetails['teachers']['jianjie'] = '暂无简介';
            }
            if (teDetails['teachers']['rongyu'] == '') {
                teDetails['teachers']['rongyu'] = '暂无荣誉';
            }
            $('#jianjie').html(teDetails['teachers']['jianjie']);
            $('#rongyu').html(teDetails['teachers']['rongyu']);
            $('#yingshi').html('');
            var html = '';
            if (teDetails['pinglun'].length != 0) {
                $.each(teDetails['pinglun'], function (k, v) {
                    var time = this.dottime;
                    this.dottime = formatDateTime(time);
                    html +='<li>'
                        +'<div class="user_himg"><img src="img/detail/user.png"/></div>'
                        + '<div>'
                        + '<p class="username">'+this.pinglunname+'</p>'
                        +'<time>'+this.dottime+'</time>'
                        +'<p>'+this.content+'</p>'
                        +'</div>'
                        + '</li>';
                })
                $('#evaluate ul').html(html);
            } else {

                $('#evaluate ul').html('<li><p>暂无评论</p></li>');
            }
        }
    },
    error: function () {
        console.log('数据加载失败');
    }

});